package com.uchedao.seller.module;

import android.text.TextUtils;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.uchedao.seller.config.GlobalInfo;
import com.uchedao.seller.util.ToastUtil;

import java.util.ArrayList;

/**
 * 综合检测
 *
 * @author "叶晋"
 */
public class Condition implements Cloneable {

    @Expose
    @SerializedName("car_type")
    public String car_type;// 车辆类型

    @SerializedName("car_type_int")
    public int car_type_int;// 车辆整型类型

    @Expose
    @SerializedName("paintPicUrl")
    public String paintPicUrl;// 漆膜厚度示意图

    @Expose
    @SerializedName("paintPicId")
    public String paintPicId;// 漆膜厚度示意图

    @Expose
    @SerializedName("paintThickness")
    // 漆膜厚度 检测结果 (0-150 未发现修复 150-250 重新喷漆,250- 喷漆并有腻子)
    public PaintThickness[] paint_thickness;

    @Expose
    @SerializedName("paintSurface")
    // 漆面检测 检测结果 ( 0 正常, 1 剐蹭, 2 变形, 3 划痕, 4 色差)
    public ResultIntArrayPics[] paint_surface = new ResultIntArrayPics[17];

    @Expose
    @SerializedName("guise")
    // 外观检测 检测结果( 0 正常, 1 无, 2 破损, 3 松旷, 4 丢失)
    public ResultIntArrayPics[] guise = new ResultIntArrayPics[24];

    @Expose
    @SerializedName("interior")
    // 内饰检测 检测结果( 0 正常, 1 破损, 2 脏污)
//	public ResultIntArray[] interior = new ResultIntArray[37];
    public ResultIntArrayPics[] interior = new ResultIntArrayPics[37];

    @Expose
    @SerializedName("config_info")
    public ConfigInfo config_info = new ConfigInfo();// 配置信息

    @Expose
    @SerializedName("function_check")
    public FunctionCheck function_check = new FunctionCheck();// 配置检测部位

    @Expose
    @SerializedName("function")
    public Function function = new Function();// 工况检测

    @Expose
    @SerializedName("performance")
    public Performance performance = new Performance();// 发动机变速箱检测

    @Expose
    @SerializedName("maintenance")
    public ArrayList<String> maintenance = new ArrayList<String>();// 保养建议

    @Expose
    @SerializedName("note")
    public String note;// 检测说明

    public Condition() {
//		for (ResultIntArrayPics arrayPics : paint_surface) {
//			arrayPics = new ResultIntArrayPics();
//			arrayPics.result = new ArrayList<Integer>();
//			arrayPics.result.add(0);
//		}
//
//		for (ResultIntArrayPics arrayPics : guise) {
//			arrayPics = new ResultIntArrayPics();
//			arrayPics.result = new ArrayList<Integer>();
//			arrayPics.result.add(0);
//		}
//
//		for (ResultIntArray array : interior) {
//			array = new ResultIntArrayPics();
//			array.result = new ArrayList<Integer>();
//			array.result.add(0);
//		}

    }

    @Override
    public Condition clone() {
        Condition condition = null;
        try {
            condition = (Condition) super.clone();
            if (paint_thickness != null) {
                condition.paint_thickness = paint_thickness.clone();
                for (int i = 0; i < paint_thickness.length; i++)
                    if (paint_thickness[i] != null)
                        condition.paint_thickness[i] = paint_thickness[i].clone();
            }
            condition.paint_surface = paint_surface.clone();
            for (int i = 0; i < paint_surface.length; i++)
                if (paint_surface[i] != null)
                    condition.paint_surface[i] = paint_surface[i].clone();

            condition.guise = guise.clone();
            for (int i = 0; i < guise.length; i++)
                if (guise[i] != null)
                    condition.guise[i] = guise[i].clone();

            condition.interior = interior.clone();
            for (int i = 0; i < interior.length; i++)
                if (interior[i] != null)
                    condition.interior[i] = interior[i].clone();

            condition.config_info = config_info.clone();
            condition.function_check = function_check.clone();
            condition.function = function.clone();
            condition.performance = performance.clone();
            condition.maintenance = (ArrayList<String>) maintenance.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return condition;
    }

    /**
     * 漆膜厚度检测是否全完成
     *
     * @return
     */
    public boolean isPaintThicknessFinish() {
        if (paint_thickness == null) {
            return false;
        }

        for (PaintThickness paintThickness : paint_thickness) {
            if (paintThickness == null || paintThickness.result == null) {
                return false;
            }
            boolean finish = false;
            for (int k : paintThickness.result) {
                // 有值大等于0，即完成
                if (k >= 0) {
                    finish = true;
                    break;
                }
            }
            if (!finish)
                return false;

        }
        return true;
    }

    /**
     * 得到状态
     *
     * @return
     */
    public int getStatus() {
        return getStatus(false);
    }

    /**
     * 得到状态
     *
     * @return
     */
    public int getStatus(boolean showToast) {
        boolean hasEmpty = false;// 有空项
        boolean hasData = false;// 有有数据项
        String message = "";

        // 若漆膜厚度检测未完成
        if (!isPaintThicknessFinish()) {
            hasEmpty = true;
            message = "【综合检测】-【漆膜厚度检测】有项目为空";
        } else {
            hasData = true;
        }

        GlobalInfo.draft.statusChildren.put("10", hasEmpty);

        String[] datas = {config_info.vin, config_info.electrically_seat, config_info.reverse_view, config_info.air,
                config_info.rear_tire_size, config_info.tool, config_info.variable_suspension,
                config_info.leather_seats, config_info.front_tire_size, config_info.hub_material,
                config_info.centre_console_lcd, config_info.smart_key, config_info.window,
                config_info.auto_adapt_drive, config_info.spare_tire, config_info.abs, config_info.electrically_window,
                config_info.back_mirror_electrically, config_info.dvd, config_info.airbag, config_info.sound_system,
                config_info.park_help, config_info.gps_navigator, config_info.booster_type,};

        boolean isEmpty1 = false;
        for (String s : datas) {
            if (TextUtils.isEmpty(s)) {
                hasEmpty = true;
                isEmpty1 = true;
                message = "【综合检测】-【配置及功能检测】-【配置信息】有项目为空";
            } else {
                hasData = true;
            }
        }

//		if (TextUtils.isEmpty(function_check.air_min_temperature)) {
//			hasEmpty = true;
//			isEmpty1 = true;
//			message = "【综合检测】-【配置及功能检测】-【配置检测部位】-【空调（出风温度）】为空";
//		} else {
//			hasData = true;
//		}

        GlobalInfo.draft.statusChildren.put("14", isEmpty1);

        boolean isEmpty2 = false;
        String[] function_datas = {function.left_front, function.left_rear, function.right_front, function.right_rear};
        for (String s : function_datas) {
            if (TextUtils.isEmpty(s)) {
                hasEmpty = true;
                isEmpty2 = true;
                message = "【综合检测】-【工况检测】-【轮胎磨损极限】有项目为空";
            } else {
                hasData = true;
            }
        }

//		System.out.println("ws----工况检测-->"+isEmpty2);
        GlobalInfo.draft.statusChildren.put("15", isEmpty2);

//		boolean isEmpty3 = false;
//		if (TextUtils.isEmpty(performance.noise_value)) {
//			hasEmpty = true;
//			isEmpty3 = true;
//			message = "【综合检测】-【发动机&变速箱】-【噪音检查】为空";
//		} else {
//			hasData = true;
//		}
//
//		GlobalInfo.draft.statusChildren.put("16",isEmpty3);

        //此处模拟图片上传的结果，因为此结果需要在图片上传页面手动进行保存才能  真实的  结果（可覆盖）
        GlobalInfo.draft.statusChildren.put("50", true);

        if (hasEmpty && hasData) {
            if (showToast)
                ToastUtil.showToastLong(message);
            return 1;// 进行中
        } else if (hasData) {
            return 2;// 已完成
        } else {
            if (showToast)
                ToastUtil.showToastLong(message);
            return 1;// 只要进来就是进行中
        }
    }
}
